#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include <QMouseEvent>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

bool MainWindow::event(QEvent *event){
    static int i=0;
    qDebug()<<i++;
    return QMainWindow::event(event);
}

void MainWindow::mousePressEvent(QMouseEvent *event)
{
    qDebug()<<"鼠标点击";
    ui->label->move(event->pos());
}

void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
{
    qDebug()<<"双击";
    if(this->isFullScreen()){
        this->showNormal();
    }else{
        this->showFullScreen();
    }
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Left) {
        QPoint pos = this->pos();
        pos.setX(pos.x() - 10);
//        this->move(pos);

        QPoint lbpos=ui->label->pos();
        lbpos.setX(lbpos.x()-10);
        ui->label->move(lbpos);
    } else if (event->key() == Qt::Key_Right) {
        QPoint pos = this->pos();
        pos.setX(pos.x() + 10);
//        this->move(pos);

        QPoint lbpos=ui->label->pos();
        lbpos.setX(lbpos.x()+10);
        ui->label->move(lbpos);
    }else if (event->key() == Qt::Key_Down) {
        QPoint pos = this->pos();
        pos.setY(pos.y() + 10);
        this->move(pos);
    }else if (event->key() == Qt::Key_Up) {
        QPoint pos = this->pos();
        pos.setY(pos.y() - 10);
        this->move(pos);
    }
}
